package com.example.fluentmybatis.dao.impl;

import com.example.fluentmybatis.dao.base.StudentScoreBaseDao;
import com.example.fluentmybatis.dao.intf.StudentScoreDao;
import com.example.fluentmybatis.dto.ScoreStatisticDTO;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * StudentScoreDaoImpl: 数据操作接口实现
 *
 * 这只是一个减少手工创建的模板文件
 * 可以任意添加方法和实现, 更改作者和重定义类名
 * <p/>@author Powered By Fluent Mybatis
 */
@Repository
public class StudentScoreDaoImpl extends StudentScoreBaseDao implements StudentScoreDao {

    @Override
    public List<ScoreStatisticDTO> statistics(Date fromYear, Date endYear, String[] subjects) {
        return super.listPoJos(ScoreStatisticDTO.class, super.query()
                .select.schoolTerm().subject()
                .count("count")
                .min.score("min_score")
                .max.score("max_score")
                .avg.score("avg_score")
                .end()
                .where.isDeleted().eq(0)
                .and.gmtCreate().between(fromYear, endYear)
                .and.subject().in(subjects)
                .end()
                .groupBy.schoolTerm().subject().end()
                .orderBy.schoolTerm().asc().subject().asc().end()
        );
    }
}
